from django.db import models

# 定义模型类，继承Model类
class Book(models.Model):
    # 属性对应的是一个字段，需要指定字段相关属性
    title = models.CharField('书名', max_length=32, default='', unique=True)
    pub = models.CharField('出版社', max_length=100, default='')
    price = models.DecimalField('价格', max_digits=7, decimal_places=2, default=0, null=True)
    market_price = models.DecimalField('图书零售价', max_digits=7, decimal_places=2, default=0)

    def __str__(self):
        return f'{self.title} {self.pub} {self.price} {self.market_price}'

    # 修改映射的表名称
    class Meta:
        db_table = 'book'

# 作家类
class Author(models.Model):
    name = models.CharField('姓名', max_length=11, null=False)
    age = models.IntegerField('年龄', default=1)
    email = models.EmailField('邮箱', null=True)
    class Meta:
        db_table = 'author'


